package com.jdz.gxq.info.admin.landinfo.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;

import com.jdz.gxq.info.admin.landinfo.bo.Landinfo;
import com.jdz.gxq.info.admin.landinfo.form.AddLandinfoForm;
import com.jdz.gxq.info.admin.landinfo.service.LandinfoService;
import com.jdz.gxq.info.common.action.CommonAction;

public class AddLandinfoAction extends CommonAction {

	private LandinfoService landinfoService = null;

	public ActionForward doExecute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws java.lang.Exception {

		AddLandinfoForm addLandinfoFrom = (AddLandinfoForm) form;

		Landinfo landinfo = addLandinfoFrom.getLandinfo();

		// landinfo名重复验证(其他后台逻辑验证也类似处理)
		if (!landinfoService.checkLandinfoName(landinfo, 1)) {
			ActionMessages messages = new ActionMessages();
			messages.add("landinfo.projectName", new ActionMessage(
					"error.landinfoNameExisted"));
			addErrors(request, messages);
			return mapping.getInputForward();
		}

		landinfo.setModifiedBy(getUserId(request));

		landinfoService.insertLandinfo(landinfo);

		return mapping.findForward("success");
	}

	public void setLandinfoService(LandinfoService landinfoService) {
		this.landinfoService = landinfoService;
	}
}
